package com.xxzb.pack0820;

import java.io.*;

//带缓冲流的字符效果
public class DemoE {
    //读取
    public static void a() throws Exception {
        File file = new File("F:\\yongpangaofeng\\a.txt");
        Reader reader = new FileReader(file);
        BufferedReader br = new BufferedReader(reader);
        //这里简化开发，获取一行信息
        String line;
        //如果没有行了就返回null
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
        reader.close();
    }
    //写入
    public static void b() throws Exception{
        File file=new File("F:\\yongpangaofeng\\d.txt");
        Writer writer=new FileWriter(file);
        //缓冲的效率更高
        BufferedWriter bw=new BufferedWriter(writer);
        bw.write("这个是我输出的一段话");
        bw.newLine();//换一行，相当于\n
        bw.flush();
        bw.close();
        writer.close();

    }

    public static void main(String[] args) throws Exception {
//        a();
        b();
    }
}
